﻿Public Class ErrorLog
    Public Property logFile As String
    Public Sub New()
        CreateLog()
    End Sub
    Public Sub CreateLog()

        'Create the log folder, file in the temp folder.
        'User user profile to find the temp folder.
        Dim tempPaht As String = Nothing
        tempPaht = IO.Path.GetTempPath()
        Dim logFolder As String = IO.Path.Combine(tempPaht, "ErrorLogs")
        'Create the logs path in the temp folder
        Try
            If Not IO.Directory.Exists(logFolder) Then
                IO.Directory.CreateDirectory(logFolder)
            End If
        Catch ex As Exception
            MessageBox.Show("Unable to Create Logs' Directory", "Error")
            MessageBox.Show(ex.ToString())
        End Try

        'Create the log file.
        Dim logName As String = System.DateTime.Today.ToString("d-M-yyyy") & ".txt"
        ' IO.File.Create(IO.Path.Combine(logFolder, logName))
        logFile = IO.Path.Combine(logFolder, logName)
    End Sub
    Public Sub WriteError(ByVal message As String)

        Using Str As New IO.StreamWriter(logFile, True)
            Str.WriteLine(message)
        End Using
    End Sub
End Class
